const { DataTypes } = require('sequelize');

module.exports = (sequelize) => {
  const Room = sequelize.define('Room', {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true,
      comment: '房间ID'
    },
    name: {
      type: DataTypes.STRING(100),
      allowNull: false,
      comment: '房间名称'
    },
    description: {
      type: DataTypes.TEXT,
      allowNull: true,
      comment: '房间描述'
    },
    image_url: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: '房间图片URL'
    },
    hourly_price: {
      type: DataTypes.DECIMAL(10, 2),
      allowNull: false,
      comment: '小时价格'
    },
    package_hours: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: '套餐小时数'
    },
    package_price: {
      type: DataTypes.DECIMAL(10, 2),
      allowNull: true,
      comment: '套餐价格'
    },
    status: {
      type: DataTypes.STRING(20),
      allowNull: false,
      defaultValue: 'available',
      comment: '房间状态：available-可用，unavailable-不可用'
    },
    roomType: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: '房间类型(0小包/1中包/2大包/3豪华包）'
    }
  }, {
    tableName: 'room',
    timestamps: true,
    createdAt: 'created_at',
    updatedAt: 'updated_at'
  });

  // 添加关联关系
  Room.associate = (models) => {
    // Room和RoomTag的一对多关系
    Room.hasMany(models.RoomTag, { 
      foreignKey: 'room_id', 
      as: 'tags' 
    });
    
    // Room和Reservation的一对多关系
    Room.hasMany(models.Reservation, {
      foreignKey: 'room_id',
      as: 'reservations'
    });
  };

  return Room;
}; 